package com.niit;

import com.niit.User;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;

/**
 * @Author cheng
 * @Date 2022 10 13 14 51
 **/


@WebServlet("/kqInfo")
public class EchartsDemo extends HttpServlet {
    public EchartsDemo() {
    }

    protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        UserDao userDAo = new UserDao();
        List<User> userList = userDAo.query();
        List<HashMap> list = new ArrayList();

        for(int i = 0; i < userList.size(); ++i) {
            HashMap map = new HashMap();
            map.put("names", ((User)userList.get(i)).getNames());
            map.put("value1", ((User)userList.get(i)).getValue1());
            map.put("value2", ((User)userList.get(i)).getValue2());

            list.add(map);
        }

        ListObject listObject = new ListObject();
        listObject.setItems(list);
        listObject.setCode(StatusCode.CODE_SUCCESS);
        listObject.setMsg("成功");


        try {

            String data =JsonUtils.toJson( listObject );
            ResponseUtils.renderJson(resp,data );

        }catch (Exception e){
            e.printStackTrace();
        }

    }

    protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        this.doGet(req, resp);
    }
}

